﻿using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;

namespace Xource.Helper
{
    public static partial class XourceHandler
    {
        public static List<ContentKeyInfo> LoadContentKeys(string filepath)
        {
            List<ContentKeyInfo> result = new List<ContentKeyInfo>();
            Stream stream = GetStreamFromFile(filepath);
            using (var package = new ExcelPackage(stream))
            {
                // Get the work book in the file
                ExcelWorkbook workBook = package.Workbook;
                if (workBook != null)
                {
                    var worksheet = workBook.Worksheets.Where(q => q.Name.Equals(_WorksheetName)).FirstOrDefault();
                    if (worksheet != null)
                    {
                        result = LoadContentKeys(worksheet);
                    }
                    else
                    {
                        throw new XourceException(string.Format("Worksheet {0} not found", _WorksheetName));
                    }
                }
            }
            return result;
        }
    }
}